/**
 * 由 WangYu 创建
 * 日期 2017/9/13
 */
import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    Image,
    TouchableOpacity,
} from 'react-native';
import HomeMunuItemView from "./HomeMunuItemView";
export default class HomeMiddleView2 extends Component {

    constructor(props) {
        super(props);
    }

    render() {
        let data=this.props.data;
        console.log(data);
        return (
            <View style={styles.container}>
                <View style={{height:60}}>
                    {this.renderItemView(data[0])}
                </View>
                <View style={{flexDirection:'row',flex:1,borderTopWidth:1,borderTopColor:'#cccccc'}}>
                    <View style={{flex:1}}>
                        {this.renderItemView(data[1])}
                        <View style={{backgroundColor:'#cccccc',height:1}} />
                        {this.renderItemView(data[2])}
                    </View>
                    <View style={{backgroundColor:'#cccccc',width:1}} />
                    <View style={{flex:1}}>
                        {this.renderItemView(data[3])}
                        <View style={{backgroundColor:'#cccccc',height:1}} />
                        {this.renderItemView(data[4])}
                    </View>
                </View>
            </View>
        );
    }

    renderItemView(data){
        return(
        <HomeMunuItemView
            titleColor={data.typeface_color}
            title={data.title}
            subTitle={data.maintitle}
            imageUri={this.dealWithImageUrl(data.imageurl)}
            onPress={()=>this.props.navigation.navigate('WebViewPage',{url:'www.baidu.com'})}/>);
    }

    dealWithImageUrl(url){
        if(url.search('w.h')===-1){
            return url;
        }else {
            return url.replace('w.h','70.60');
        }
    }
}

const styles = StyleSheet.create({
    container: {
        height:180,
        backgroundColor:'white'
    },
});
